package com.strat.searcher.lucene.files;

import java.io.File;
import java.io.IOException;

import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.strat.searcher.exceptions.IndexingException;
import com.strat.searcher.lucene.searching.Searcher;

public class FileUtil {

    private static Logger logger = LoggerFactory.getLogger(Searcher.class);

    public static Directory getDirectory(File dirFile) {
        Directory dir;
        try {
            dir = FSDirectory.open(dirFile);
            return dir;
        } catch (IOException e) {
            logger.error("error", e);
            throw new IndexingException(e);
        }
    }

    public static Directory getDirectory(String dirFileName) {
        File dirFile;
        dirFile = new File(dirFileName);
        return FileUtil.getDirectory(dirFile);
    }
}
